 #define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int reverse(int x) {
        string s = to_string(x);
        int l = 0;
        if (s[l] == '-') {
            l++;
        }
        std::reverse(s.begin() + l, s.end());
        const int k1 = INT_MAX, k2 = INT_MIN;
        string t1 = to_string(k1), t2 = to_string(k2);
        if (s[0] == '-') {
            if (s.length() == t2.length() && s > t2) {
                return 0;
            }
        }
        else {
            if (s.length() == t1.length() && s > t1) {
                return 0;
            }
        }
        x = stoi(s);
        return x;
    }
};
